package cece.controller;

import cece.entity.Address;
import cece.entity.Item;
import cece.entity.ItemNew;
import cece.entity.QueryResult;
import cece.service.AddressService;
import cece.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther Programmer
 * @Date 2020-05-22 17:10
 */
@RestController
@RequestMapping("/bean")
public class BeanFlowerController {

	@Autowired
	private ItemService itemService;

	@Autowired
	private AddressService addressService;

	@GetMapping("/get")
	public String testGet() {
		return "index";
	}


	@GetMapping("/findAll")
	public List<Item> findAll() {
		return itemService.findAll();
	}

	@GetMapping("/hot")
	public List<ItemNew> findHot() {
		return itemService.findHot();
	}

	@GetMapping("/findByPage/{page}/{size}")
	public QueryResult findByPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
		return itemService.findByPage(page, size);
	}

	@GetMapping("/findAddress")
	public List<Address> findAddress() {
		return addressService.findAll();
	}

	@PostMapping("/updateAddress")
	public String updateAddress(Address address) {
		return addressService.update(address);
	}
}
